package cn.jiyun.controller;

import cn.jiyun.pojo.User;
import cn.jiyun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("findAll")
    @ResponseBody
    public List<User> findAll(){
        List<User> list=userService.findAll();
        System.out.println("list==========="+list);
        return list;
    }
    @RequestMapping("deleteById/{id}")
    @ResponseBody
    public Integer deleteById(@PathVariable("id") Integer id){
        int b= userService.deleteById(id);
        return b;
    }
    @RequestMapping("update")
    @ResponseBody
    public Integer updateById(){
        User user = new User(2, "啦啦啦啦", 20, "男", 2);
        int b=userService.updateById(user);
        return b;
    }
    @RequestMapping("add")
    @ResponseBody
    public List<User> add(){
        User user = new User(10, "武器", 23, "男",3);
        userService.add(user);
        List<User> list=userService.findAll();
        return list;
    }
}
